package com.xbongbong.paas.script.enums;

import com.xbongbong.saas.enums.XbbRefTypeEnum;
import lombok.Getter;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Set;

/**
 * 用户不可编辑的字段, 该文件中的attrName不需要国际化处理
 * @Description
 * @author: shian
 * @date : 2021/3/3
 */
@Getter
public enum I18nHideFieldEnum {
    /**
     * 客户：主联系人名称、主联系人电话、分配时间、是否归档（作用于导出）
     */
    CUSTOMER_CONTACT_NAME(XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode(),"text_12", "主联系人名称", "Primary contact name"),
    CUSTOMER_CONTACT_PHONE(XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode(), "subForm_2", "主联系人电话", "Primary contact phone"),
    CUSTOMER_DISTRIBUTION_DATE(XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode(), "date_4", "分配时间", "Allocation time"),
    CUSTOMER_IS_ARCHIVED(XbbRefTypeEnum.CUSTOMER_MANAGEMENT.getCode(), "num_4", "是否归档", "Is Archived"),

    /**
     * 合同：已收金额、未收金额、坏账金额、收款比例、开票金额、未开票金额、归档状态
     */
    CONTRACT_FINISH_AMOUNT(XbbRefTypeEnum.CONTRACT.getCode(), "num_6", "已收金额", "Amount received"),
    CONTRACT_UN_FINISH_AMOUNT(XbbRefTypeEnum.CONTRACT.getCode(), "num_7", "未收金额", "Outstanding amount"),
    CONTRACT_BAD_AMOUNT(XbbRefTypeEnum.CONTRACT.getCode(), "num_31", "坏账金额", "Amount of bad debts"),
    CONTRACT_PAY_PERCENT(XbbRefTypeEnum.CONTRACT.getCode(), "num_8", "收款比例", "Collection ratio"),
    CONTRACT_INVOICE_AMOUNT(XbbRefTypeEnum.CONTRACT.getCode(), "num_9", "开票金额", "Amount of invoice"),
    CONTRACT_UN_INVOICE_AMOUNT(XbbRefTypeEnum.CONTRACT.getCode(), "num_10", "未开票金额", "Unbilled amount"),
    CONTRACT_ARCHIVED(XbbRefTypeEnum.CONTRACT.getCode(), "num_11", "归档状态", "Archiving Status"),
    /**
     * 机会：最后跟进时间
     */
    OPPORTUNITY_LAST_CONNECT_TIME(XbbRefTypeEnum.SALES_OPPORTUNITY.getCode(),"date_2", "最后跟进时间", "Last follow-up time"),

    /**
     * 工单：耗时状况、工单状态、完成时间、关闭时间、评价星级、阶段状态、阶段名称
     */
    WORK_ORDER_TIME_OUT(XbbRefTypeEnum.WORK_ORDER.getCode(), "text_12", "耗时状况", "Time consuming condition"),
    WORK_ORDER_STATUS(XbbRefTypeEnum.WORK_ORDER.getCode(),"status", "工单状态", "Work order status"),
    WORK_ORDER_COMPLETE_TIME(XbbRefTypeEnum.WORK_ORDER.getCode(),"endTime", "完成时间", "Completion time"),
    WORK_ORDER_CLOSE_TIME(XbbRefTypeEnum.WORK_ORDER.getCode(),"closeTime", "关闭时间", "Closing time"),
    WORK_ORDER_RATE_STAR(XbbRefTypeEnum.WORK_ORDER.getCode(),"num_2", "评价星级", "Rating star"),
    WORK_ORDER_NODE_STATUS(XbbRefTypeEnum.WORK_ORDER.getCode(),"num_3", "阶段状态", "Stage state"),
    WORK_ORDER_STAGE_NAME(XbbRefTypeEnum.WORK_ORDER.getCode(),"text_14", "阶段名称", "Stage name"),


    /**
     * 采购合同：实付金额、付款比例、未付金额
     */
    PURCHASE_FINISH_AMOUNT(XbbRefTypeEnum.PURCHASE.getCode(), "num_32", "实付金额", "Actual amount paid"),
    PURCHASE_RECEINE_PERCENT(XbbRefTypeEnum.PURCHASE.getCode(), "num_34", "付款比例", "Payment ratio"),
    PURCHASE_UN_FINISH_AMOUNT(XbbRefTypeEnum.PURCHASE.getCode(), "num_33", "未付金额", "Unpaid amount"),


    /**
     * 报价单组号
     */
    QUOTATION__UN_VERSION(XbbRefTypeEnum.QUOTATION.getCode(), "text_8", "报价单组号", "Version"),
    QUOTATION__UN_GROUP_NUMBER(XbbRefTypeEnum.QUOTATION.getCode(), "text_14", "版本号", "Group number"),
    /**
     * 访客计划
     */
    COMMUNICATE_PLAN__CONTRACT_WAY(XbbRefTypeEnum.COMMUNICATE_PLAN.getCode(), "subForm_1", "联系方式", "Contract way"),
    /**
     * 销售线索 是否归档
     */
    CLUE_DISTRIBUTION_DATE(XbbRefTypeEnum.CLUE.getCode(), "date_3", "分配时间", "Allocation time"),
    CLUE_IS_ARCHIVED(XbbRefTypeEnum.CLUE.getCode(), "num_3", "是否归档", "Is Archived"),
    /**
     * 工单
     */
    WORK_ORDER_STAGE(XbbRefTypeEnum.WORK_ORDER.getCode(), "stage_id", "阶段", "stage"),

    /*
     * 工单负责人
     */
    WORK_ORDER_MANAGER_ID(XbbRefTypeEnum.WORK_ORDER.getCode(), "text_11", "工单负责人", "Owner of work order"),


    /*
     * 工作 日报 周报 月报
     */
    WORKREPORT_DAILY_CONTENT(XbbRefTypeEnum.WORKREPORT_DAILY.getCode(), "subForm_2", null, null,true,"text_1","Plan content"),
    WORKREPORT_WEEKLY_CONTENT(XbbRefTypeEnum.WORKREPORT_WEEKLY.getCode(), "subForm_2", null, null,true,"text_1","Plan content"),
    WORKREPORT_MONTHLY_CONTENT(XbbRefTypeEnum.WORKREPORT_MONTHLY.getCode(), "subForm_2", null, null,true,"text_1","Plan content"),

    ;

    /**
     * 业务类型
     */
    private int businessType;

    /**
     * 字段标识
     */
    private String attr;

    /**
     * 字段中文名称
     */
    private String attrName;

    /**
     * 字段英文名称
     */
    private String attrNameEn;

    /*
     * 是否有子表单
     */
    private  boolean hasSubForm;

    /*
     * 子表单字段标识
     */
    private String subAttr;

    /*
     * 子表单字段英文名称
     */
    private String subAttrNameEn;


    I18nHideFieldEnum(int businessType, String attr, String attrName, String attrNameEn) {
        this.businessType = businessType;
        this.attr = attr;
        this.attrName = attrName;
        this.attrNameEn = attrNameEn;
        this.hasSubForm = false;  // 默认没有子表单
    }

    I18nHideFieldEnum(int businessType, String attr, String attrName, String attrNameEn,boolean hasSubForm,String subAttr,String subAttrNameEn) {
        this.businessType = businessType;
        this.attr = attr;
        this.attrName = attrName;
        this.attrNameEn = attrNameEn;
        this.hasSubForm = hasSubForm;
        this.subAttr = subAttr;
        this.subAttrNameEn = subAttrNameEn;
    }

    public static List<Integer> getAllBusinessType() {
        Set<Integer> businessTypeSet = new HashSet<>();
        for (I18nHideFieldEnum anEnum : values()) {
            businessTypeSet.add(anEnum.getBusinessType());
        }
        return new ArrayList<>(businessTypeSet);
    }

    public static I18nHideFieldEnum getByBusinessTypeAndAttr(int businessType, String attr) {
        for (I18nHideFieldEnum anEnum : values()) {
            if (Objects.equals(businessType, anEnum.getBusinessType()) && Objects.equals(attr, anEnum.getAttr())) {
                return anEnum;
            }
        }
        return null;
    }

    public static List<I18nHideFieldEnum> getByBusinessType(int businessType) {
        List<I18nHideFieldEnum> fieldEnums = new ArrayList<>();
        for (I18nHideFieldEnum anEnum : values()) {
            if (Objects.equals(businessType, anEnum.getBusinessType())) {
                fieldEnums.add(anEnum);
            }
        }
        return fieldEnums;
    }
}
